#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qdebug.h"

MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    connect(ui->btnStart, &QPushButton::clicked, this, &MainWindow::onBtnStartClicked);
    connect(ui->btnConnect, &QPushButton::clicked, this, &MainWindow::onBtnConnectClicked);
}

MainWindow::~MainWindow()
{
    delete ui;
}

/**
 * 点击 启动&停止按钮
 * @brief MainWindow::onBtnStartClicked
 */
void MainWindow::onBtnStartClicked()
{
    QString str = ui->btnStart->text();

    qDebug() << str;

    if(str == "启动"){
        ui->btnStart->setText("停止");
        ui->btnStart->setIcon(QIcon(":/icon/stop.ico"));
    } else {
        ui->btnStart->setText("启动");
        ui->btnStart->setIcon(QIcon(":/icon/start.ico"));
    }
}

/**
 * 点击 发送按钮
 * @brief MainWindow::onBtnConnectClicked
 */
void MainWindow::onBtnConnectClicked()
{
    QString str = ui->btnConnect->text();

    if(str == "连接"){
        ui->btnConnect->setText("断开连接");
        ui->btnSend->setEnabled(true);
    } else {
        ui->btnConnect->setText("连接");
        ui->btnSend->setEnabled(false);
    }
}
